package com.atguigu.dao.impl;

import com.atguigu.bean.Book;
import com.atguigu.dao.BaseDao;
import com.atguigu.dao.BookDao;

import java.util.List;

public class BookDaoImpl extends BaseDao<Book> implements BookDao{
    @Override
    public boolean saveBook(Book book) {
        String sql="insert into books values(null,?,?,?,?,?,?)";
      return this.update(sql,book.getTitle(),book.getAuthor(),book.getPrice(),book.getSales(),book.getStock(),book.getImg_path());

    }

    @Override
    public List<Book> findAllBook() {
        String sql="select * from books";
        return this.getBeanList(Book.class, sql);
    }

    @Override
    public void deleteBookById(String id) {
        String sql="delete from books where id=?";
        this.update(sql,id);
    }

    @Override
    public Book selectBookById(String id) {
        String sql="select * from books where id=?";
        return this.getBean(Book.class,sql,id);
    }

    @Override
    public void updateBookById(Book book) {
        String sql="update books set title=? , price=? ,author=?,sales=? ,stock=?  where id=?" ;
       update(sql,book.getTitle(),book.getPrice(),book.getAuthor(),book.getSales(),book.getStock(),book.getId());

    }
}
